package com.appspot.categoryeditor.resource;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

public class AbstractResource {

	protected static boolean checkLogin(HttpServletRequest req) {
		return req.getUserPrincipal() != null;
	}

	protected static void redirectToLoginUrl(
			HttpServletRequest req,
			HttpServletResponse resp) {
		UserService userService = UserServiceFactory.getUserService();
		try {
			resp.sendRedirect(userService.createLoginURL(req.getRequestURI()));
		} catch (IOException e) {
		}
	}
	
}
